#region Copyright (c) 2006 Jonathan Nauman
/*       _\|/_
         (o o)
+-----oOO-{_}-OOo-----------------------+
| Copyright (c) Jonathan Naumann        |
+---------------------------------------+
| 
| File: MonoPad.Preferences.cs
| Version:	0.1.1
+
*/
#endregion

//#define __DEBUG

using System;
using Gtk;
//using Glade;

namespace MonoPad {
	///
	/// Class Preferences
	///
	public class Preferences {
		private Glade.XML oGXML = null;
		private ConfigProvider cnfload = new ConfigProvider();
		
		[Glade.Widget]
		Window prefWindow;
		
		[Glade.Widget]
		TreeView tvMain;
		
		[Glade.Widget]
		CheckButton chkLinenumbers;
		
		[Glade.Widget]
		CheckButton chkMonotypeFont;
		
		[Glade.Widget]
		SpinButton spTabWidth;
		
		///
		/// Default Constructor
		///
		public Preferences() {
			#if __DEBUG
				Console.WriteLine("MonoPad -> Open preferences dialog ...");
			#endif
			oGXML = new Glade.XML(null, "gui.glade", "prefWindow", null);
			oGXML.Autoconnect(this);
			
			// config
			ConfigContainer config = cnfload.GetConfiguration();
			
			try {
				chkLinenumbers.Active = config.LineNumbers;
				chkMonotypeFont.Active = config.MonotypeFont;
				spTabWidth.Value = Convert.ToDouble(config.TabWidth);
			}
			catch(Exception ex) {
				Console.WriteLine("ERROR: " + ex.Message);
			}
		}
		
		// ------------------------------------
		// Button events
		// ------------------------------------
		
		///
		/// Event for the open button
		///
		private void on_btnCancel_clicked(object o, EventArgs args) {
			#if __DEBUG
				Console.WriteLine("MonoPad -> Close preferences dialog ...");
			#endif
			prefWindow.Destroy();
		}
		
		///
		/// Event for the open button
		///
		private void on_btnOk_clicked(object o, EventArgs args) {
			ConfigContainer config = cnfload.GetConfiguration();
			
			try {
				config.LineNumbers = chkLinenumbers.Active;
				config.MonotypeFont = chkMonotypeFont.Active;
				config.TabWidth = Convert.ToUInt32(spTabWidth.ValueAsInt);
				
				cnfload.SetConfiguration(config);
				
				#if __DEBUG
					Console.WriteLine("MonoPad -> Save settings and close preferences dialog ...");
				#endif
			}
			catch(Exception ex) {
				Console.WriteLine("ERROR: " + ex.Message);
			}
			
			prefWindow.Destroy();
		}
	}
}
